package com.workcell.workdata.xthings.kafka.sender;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.kafka.support.ProducerListener;
import org.springframework.stereotype.Component;

import javax.annotation.Nullable;

/**
 * @Author 廖博文
 * @Date 2023/5/25 10:17
 * @Description 监听发送消息
 */
@Slf4j
@Component
public class KafkaSendResultHandler implements ProducerListener<Object, Object> {

	@Override
	public void onSuccess(ProducerRecord producerRecord, RecordMetadata recordMetadata) {
		log.info("Kafka消息队列发送日志，发送后成功：topic[{}]，value[{}]", producerRecord.topic(), producerRecord.value());
	}

	@Override
	public void onError(ProducerRecord producerRecord, @Nullable RecordMetadata recordMetadata, Exception exception) {
		log.error("Kafka消息队列发送日志，发送后异常：topic[{}]，value[{}]，异常[{}]", producerRecord.topic(), producerRecord.value(),exception.getMessage());
	}

}
